//
//  SplashScreenView.swift
//  casdon_swiftUI
//
//  Created by ww on 2025/3/30.
//

import SwiftUI
struct SplashScreenView: View {
    @State private var isActive = false
    @State private var opacity = 0.0
    @StateObject private var authManager = AuthManager.shared

    var body: some View {
        
        if isActive {
           
            if authManager.isLoggedIn/* && authManager.istuyaLogin*/{
                MainTabView()
                    .transition(.opacity)
            } else {
                LoginStackView().transition(.opacity)
            }
        } else {
            // 启动页面
            ZStack {
                Spacer()
            }.background(
                Image("launchkd")
                    .resizable()
                    .scaledToFill()
                    .edgesIgnoringSafeArea(.all)
            )

            .onAppear {
                // Logo淡入效果
                withAnimation(.easeIn(duration: 0.8)) {
                    opacity = 1.0
                }

                // 延迟后切换到主界面
                DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
                    withAnimation(.easeOut(duration: 0.3)) {
                        self.isActive = true
                    }
                }
            }
        }
    }
}

struct SplashScreenView_Previews: PreviewProvider {
    static var previews: some View {
        SplashScreenView()
    }
}
